package com.laoye.big_event.Exception;

import com.laoye.big_event.Pojo.Result;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
//统一异常管理
public class GlobalHandlerException {
    @ExceptionHandler(Exception.class)
    public Result handlerException(Exception e) {
        //打印异常信息
        e.printStackTrace();
        //判断有异常输出异常信息，没有返回操作失败
        return Result.error(StringUtils.hasLength(e.getMessage()) ? e.getMessage() : "操作失败");
    }
}
